package org.su.generalmvc.validate;

import org.apache.commons.lang.StringUtils;
import org.apache.oro.text.perl.Perl5Util;


/**
 * 格式校验器
 * @author liuxuankun
 *
 */
public class Validater {
	private static Perl5Util validateMatcher = new Perl5Util();

	/**
	 * email 正则表达式
	 */
	public static final String email = "/^[a-z0-9]([a-z0-9]*[-_\\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\\.][a-z]{2,3}([\\.][a-z]{2})?$/i";//"/^[A-Za-z0-9_]+([A-Za-z0-9_\\.][A-Za-z0-9_]+)*@[A-Za-z0-9_]+(\\.[A-Za-z0-9_]+)*\\.[A-Za-z0-9_]+([-.][A-Za-z0-9_]+)*$/";
	public static final String phone = "/(^(\\d{2,4}[-_－—]?)?\\d{3,8}([-_－—]?\\d{3,8})?([-_－—]?\\d{1,7})?$)|(^0?1\\d{10}$)/";
	public static final String mulPhone = "^((\\d{3,4}){0,1}\\-{0,1}\\d{7,8})(\\,(\\d{3,4}){0,1}\\-{0,1}\\d{7,8})*$/";
	public static final String mobile = "/^1\\d{10}$/";
	public static final String Url = "/^http:\\/\\/[A-Za-z0-9]+\\.[A-Za-z0-9]+[\\/=\\?%\\-&_~`@[\\]\\':+!]*([^<>\"\"])*$/";
	public static final String IdCard = " /^\\d{15}(\\d{2}[A-Za-z0-9])?$/";
	public static final String Currency = "/^\\d+(\\.\\d+)?$/";
	public static final String _number = "/^\\d+$/";
	public static final String Zip = "/^[1-9]\\d{5}$/";
	public static final String QQ = "/^[1-9]\\d{4,8}$/";
	public static final String _integer = "/^[-\\+]?\\d+$/";
	public static final String positiveInteger = "/^[1-9]\\d*|0$/";
	public static final String _double = "/^[-\\+]?\\d+(\\.\\d+)?$/";
	public static final String english = "/^[A-Za-z]+$/";
	public static final String AccountId = "/^[A-Za-z|0-9|_|\u0391-\uFFE5]+$/";
	public static final String chinese = "/^[\u4E00-\u9FA5]+$/";

	/* (non-Javadoc)
	 * @see ssh.generalmvc.web.validate.IModel#validateRequire(java.lang.String, java.lang.String, java.lang.String)
	 */
	public static boolean validateRequire(String value) {
		return StringUtils.isNotEmpty(value);
	}

	/* (non-Javadoc)
	 * @see ssh.generalmvc.web.validate.IModel#validateEmail(java.lang.String, java.lang.String, java.lang.String)
	 */
	public static boolean validateMatch(String regex, String value) {
		if(StringUtils.isNotEmpty(value) ) {
			return validateMatcher.match(regex,	value);
		}else{
			return true;
		}
	}
}
